<?php

App::uses('AppController', 'Controller');

/**

 * PropertyTypes Controller

 *

 * @property PropertyType $PropertyType

 * @property PaginatorComponent $Paginator

 * @property SessionComponent $Session

 */

class PropertyTypesController extends AppController {




	public $components = array('Paginator', 'Session');



	public function admin_index() {
		$this->PropertyType->recursive = 0;
		$this->set('propertyTypes', $this->Paginator->paginate());
	}



	public function admin_view($id = null) {
		if (!$this->PropertyType->exists($id)) {
			throw new NotFoundException(__('Invalid property type'));
		}
		$options = array('conditions' => array('PropertyType.' . $this->PropertyType->primaryKey => $id));
		$this->set('propertyType', $this->PropertyType->find('first', $options));
	}



	public function admin_add() {
		if ($this->request->is('post')) {
			$this->PropertyType->create();
			if ($this->PropertyType->save($this->request->data)) {
				$this->Session->setFlash(__('The property type has been saved.'), 'default', array('class' => 'alert alert-success'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The property type could not be saved. Please, try again.'), 'default', array('class' => 'alert alert-danger'));
			}

		}

	}


	public function admin_edit($id = null) {
		if (!$this->PropertyType->exists($id)) {
			throw new NotFoundException(__('Invalid property type'));
		}

		if ($this->request->is(array('post', 'put'))) {
			if ($this->PropertyType->save($this->request->data)) {
				$this->Session->setFlash(__('The property type has been saved.'), 'default', array('class' => 'alert alert-success'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The property type could not be saved. Please, try again.'), 'error', array('class' => 'alert alert-danger'));
			}

		} else {
			$options = array('conditions' => array('PropertyType.' . $this->PropertyType->primaryKey => $id));
			$this->request->data = $this->PropertyType->find('first', $options);
		}

	}


	public function admin_delete($id = null) {
		$this->PropertyType->id = $id;
		if (!$this->PropertyType->exists()) {
			throw new NotFoundException(__('Invalid property type'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->PropertyType->delete()) {
			$this->Session->setFlash(__('The property type has been deleted.'), 'default', array('class' => 'alert alert-success'));
		} else {
			$this->Session->setFlash(__('The property type could not be deleted. Please, try again.'), 'error', array('class' => 'alert alert-danger'));

		}
		return $this->redirect(array('action' => 'index'));

	}

}

